// 路径
import path from 'path';
import vue from "@vitejs/plugin-vue"
import { defineConfig } from 'vite'
// 自动导入插件
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// element Icon组件 自动导入
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'

const pathSrc = path.resolve(__dirname, 'src')

export default defineConfig({
  resolve: {
    alias: {
      '@': pathSrc
    },
  },
  plugins: [
    vue(),
    // ElementPlus({}),
    AutoImport({
      // 自动导入 Vue 相关函数，如：ref, reactive, toRef 等
      imports: ['vue'],
      resolvers: [ElementPlusResolver(),
      // 自动导入图标组件
      IconsResolver({
        prefix: 'Icon',
      }),
      ],
    }),
    Components({
      resolvers: [ElementPlusResolver(),// 自动注册图标组件
      IconsResolver({
        enabledCollections: ['ep'],
      }),

      ],
      dts: path.resolve(pathSrc, 'components.d.ts'),
    }),
    Icons({
      autoInstall: true,
    }),
  ],
  css: {
    preprocessorOptions: {
      less: {
        // 这里可以添加全局的 Less 变量或者 mixins
        modifyVars: {
          'primary-color': '#4CAF50',
        },
        javascriptEnabled: true,
      },
    },
  },
})